package com.jumi.microservice.controller.api;

import com.jm.member.common.jwt.annon.IgnoreUrlsAnnon;
import com.jm.member.common.messages.entity.TicketResponse;
import com.jm.member.common.messages.entity.WeChartResponse;
import com.jm.member.common.messages.service.WeChartService;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.util.If;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/share")
@Api(value = "C-分享",tags = "C-分享")
public class ShareController {

    @Autowired
    WeChartService chartService;


    @GetMapping("/getTicketResponse")
    @IgnoreUrlsAnnon("/getTicketResponse")
    @ApiOperation(tags = "获取加密后的分享链接",value = "获取加密后的分享链接")
    public ResponseResult<TicketResponse> getTicketResponse(String url){
        TicketResponse response;
        WeChartResponse shareAccessToken = chartService.getShareAccessToken();
        String access_token = shareAccessToken.getAccess_token();
        If.ifStr(access_token,"请求AccessToken失败!");
        WeChartResponse shareTicket = chartService.getShareTicket(shareAccessToken.getAccess_token());
        String ticket = shareTicket.getTicket();
        If.ifStr(ticket,"请求ticket失败!");
        response = chartService.getTicketResponse(ticket, url);
        return ResponseResult.success(response);
    }


}
